import java.util.*;
import java.io.*;
import java.math.*;
public class p1007
{
    static public void main(String[] args) throws IOException
    {
        Scanner cin = new Scanner(new BufferedInputStream(System.in));
        BigInteger prime[] = new BigInteger[80],  n;
        int shai[] = new int[300];
        int k, i, j, num, t;
        for (i = 0; i < 300; i++)
            shai[i] = 1;
        k = 0;
        for (i = 2; i < 250; i++)
        {
            if (shai[i] == 1)
            {
                prime[k] = BigInteger.valueOf(i);
                k++;
                for (j = i * 2; j < 242; j += i)
                    shai[j] = 0;
            }
        }
        for (i = 1; i < k; i++)
            prime[i] = prime[i].multiply(prime[i-1]);
        t = cin.nextInt();
        while (true)
        {
            if (t == 0)
                break;
            t--;
            n = cin.nextBigInteger();
            for (i = 0; i < k; i++)
                if (n.compareTo(prime[i]) == -1)
                    break;
            System.out.println(prime[i-1]);
        }
    }
}

